package com.atguigu.gmall.index.controller;

import com.atguigu.gmall.common.bean.ResponseVo;
import com.atguigu.gmall.index.service.IndexService;
import com.atguigu.gmall.pms.entity.CategoryEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author mahaijun
 * @version 1.0.0
 * @ClassName IndexController.java
 * @Description TODO
 * @createTime 2021年11月12日 20:38:00
 */
@Controller
public class IndexController {
    @Autowired
    private IndexService indexService;
    @GetMapping({"/","/**"})
    public String toIndex(Model model){
        List<CategoryEntity> categoryEntityList = indexService.queryLv1Cates();
        model.addAttribute("categories",categoryEntityList);
        return "index";
    }
    @ResponseBody
    @GetMapping("/index/cates/{pid}")
    public ResponseVo<List<CategoryEntity>> queryLv123CatesByPid(@PathVariable("pid") Long pid){
         List<CategoryEntity> categoryEntities = this.indexService.queryLv123CatesByPid(pid);
         return ResponseVo.ok();
    }

}
